package com.ruoyi.model.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.model.domain.vo.ModelPlanVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.model.domain.ModelPlan;
import com.ruoyi.model.service.IModelPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型方案Controller
 *
 * @author rww
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/model/plan")
public class ModelPlanController extends BaseController
{
    @Autowired
    private IModelPlanService modelPlanService;

    /**
     * 查询模型方案列表
     */
    @PreAuthorize("@ss.hasPermi('model:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelPlan modelPlan)
    {
        startPage();
        List<ModelPlan> list = modelPlanService.selectModelPlanList(modelPlan);
        return getDataTable(list);
    }
    /**
    * 查询模型方案列表-不带分页
    * */
    @GetMapping("/noPageList")
    public AjaxResult noPageList(ModelPlan modelPlan)
    {
        List<ModelPlan> list = modelPlanService.selectModelPlanList(modelPlan);
        return AjaxResult.success(list);
    }
    /**
     * 导出模型方案列表
     */
    @PreAuthorize("@ss.hasPermi('model:plan:export')")
    @Log(title = "模型方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelPlan modelPlan)
    {
        List<ModelPlan> list = modelPlanService.selectModelPlanList(modelPlan);
        ExcelUtil<ModelPlan> util = new ExcelUtil<ModelPlan>(ModelPlan.class);
        util.exportExcel(response, list, "模型方案数据");
    }

    /**
     * 获取模型方案详细信息
     */
//    @PreAuthorize("@ss.hasPermi('model:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(modelPlanService.selectModelPlanVoById(id));
    }

    /**
     * 新增模型方案
     */
    @PreAuthorize("@ss.hasPermi('model:plan:add')")
    @Log(title = "模型方案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ModelPlanVo modelPlan)
    {
        return toAjax(modelPlanService.insertModelPlan(modelPlan));
    }

    /**
     * 修改模型方案
     */
    @PreAuthorize("@ss.hasPermi('model:plan:edit')")
    @Log(title = "模型方案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ModelPlanVo modelPlan)
    {
        return toAjax(modelPlanService.updateModelPlanVo(modelPlan));
    }

    /**
     * 删除模型方案
     */
    @PreAuthorize("@ss.hasPermi('model:plan:remove')")
    @Log(title = "模型方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(modelPlanService.deleteModelPlanByIds(ids));
    }
}
